<!DOCTYPE html>
<html lang="en">
<head>
    <title>集团管理层-客户报表</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <link rel="stylesheet" href="/dist/plugins/select2/select2.min.css">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=86e2297f">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=222aea35">
    <style>
        .row {
            margin-right: -15px;
            margin-left: 0px;
        }
        .col-lg-6,.col-xs-6,.col-md-6{
            padding-left: 0;
        }
    </style>
</head>
<body>
<section class="content" id="list">

    <div v-if="userId.length>0" class="nav-tabs-custom oaReportNav">
        <!-- Tabs within a box -->
        <ul class="nav nav-tabs pull-right" style="margin-bottom: 10px;"   v-cloak>
            <li class="active"><a href="#revenue-chart" data-toggle="tab">今天</a></li>
            <li><a href="#revenue-chart" data-toggle="tab">本月</a></li>
            <li v-for="(item,i) in months"><a href="#sales-chart" data-toggle="tab">{{item}}</a></li>
        </ul>
    </div>
    <div class="box-body no-padding" style="overflow: auto;background: #fff;">
        <table class="table table-bordered" style="max-width: 550px" cellspacing= "0">
            <thead>
            <tr>
                <th style="width: 100px;text-align: center">大区</th>
                <th style="width: 90px;text-align: center">大区经理</th>
                <th style="width: 100px;text-align: center">
                    客户数量<span v-if="hour<12&&dateTime==today">(昨日)</span>
                </th>

            </tr>
            </thead>
            <tbody   v-cloak>
            <tr v-for="(item, i) in list">
                <td style="text-align: center" >{{item.departName}}</td>
                <td style="text-align: center">{{item.managerName}}</td>
                <td style="text-align: center;color:#169BD5;cursor: pointer" @click="lookRegionList(item)" >{{item.visitCount}}</td>
            </tr>
            <tr class="text-center"><td>合计</td><td>/</td><td>{{allCount.regionManagerNum}}</td></tr>
            </tbody>
        </table>
    </div>
    <!-- /.box-body -->
</section>
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=8e743a31"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=54c6b89c"></script>
<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">

    var app = new Vue({
        el: '#list',
        data: {
            list:[
            ],
            months:[],
            currentUser: getCurrentUser(),
            readerName: "",
            userId: getCurrentUser().id,
            dateTime:new Date().Format("yyyy-MM-dd"),
            today:new Date().Format("yyyy-MM-dd"),
            hour:new Date().getHours(),
            companyId:$.wyui.page.urlParams.companyId,
            allCount:{"regionManagerNum":"","complete":"","managerTargetNum":"","bigManagerNum":""}
        },
        methods: {
            //  查看下属
            lookRegionList:function (item) {
                var that = this;
                top.closeTabByPageId("khbb-big");
                url = "reportForm/customer/regionList.html?companyId="+item.companyId+"&dateTime="+this.dateTime;
                top.addTabs({id:"khbb-big",title:item.companyName,close: true,url:url});
            },
            getLastEndMonth: function (beginYearMonth) {
                var strYear = parseInt(beginYearMonth.substr(0, 4), 10);
                var strMonth = parseInt(beginYearMonth.substr(4, 6), 10);
                if (strMonth - 1 == 0) {
                    strYear -= 1;
                    strMonth = 12;
                } else {
                    strMonth -= 1;
                }
                if (strMonth < 10) {
                    strMonth = "0" + strMonth;
                }
                var monthstr = strYear + "" + strMonth;
                return monthstr;
            },
            insert_flg:function (str,flg,sn) {
                var newstr="";
                for(var i=0;i<str.length;i+=sn){
                    var tmp=str.substring(i, i+sn);
                    console.log(tmp)
                    newstr+=tmp+flg;
                }
                newstr = newstr.substr(0,newstr.length-1);
                return newstr;
            },
            isHasRightOp: function (eName) {
                console.log($.inArray(eName, this.reginIds) > -1)
                return $.inArray(eName, this.reginIds) > -1;
            },
            getMonths: function () {
                var that = this;
                var dateTime = new Date().Format("yyyyMM");
                for (var i = 0; i < 4; i++) {
                    dateTime = that.getLastEndMonth(dateTime);
                    that.months.push(that.insert_flg(dateTime, "-", "4"))
                }
            },

            tablesMergeCell:function(list){
                for (field in list[0]) {
                    var k = 0;
                    while (k < list.length) {
                        list[k][field + 'span'] = 1;
                        list[k][field + 'dis'] = false;
                        for (var i = k + 1; i <= list.length - 1; i++) {
                            if (list[k][field] == list[i][field] && list[k][field] != '') {
                                list[k][field + 'span']++;
                                list[k][field + 'dis'] = false;
                                list[i][field + 'span'] = 1;
                                list[i][field + 'dis'] = true;
                            } else {
                                break;
                            }
                        }
                        k = i;
                    }
                }
                return list;
            },
            getCount:function (arr,key) {
                var number=0;
                for (var i = arr.length - 1; i >= 0; i--) {
                    number+=(arr[i][key]?arr[i][key]:0)

                }
                return number;
            },
            getAllCounnt:function (arr) {
                this.allCount.regionManagerNum=this.getCount(arr,"regionManagerNum");
                this.allCount.complete=this.getCount(arr,"complete");
                this.allCount.managerTargetNum=this.getCount(arr,"managerTargetNum");
                this.allCount.bigManagerNum=this.getCount(arr,"bigManagerNum");
            },
            //  初始化菜单
            initList: function () {
                var that = this;
                $.wyui.postMethod(urlConfig.crm.customer.getRegionByManageDQ, {
                    "dateTime":that.dateTime,"companyId":that.companyId
                } , function (data) {
                    console.log(data);
                    that.list = that.tablesMergeCell(data);
                    that.getAllCounnt(that.list)

                });
            }
        },

        mounted: function () {
            //获取前5个月
            this.getMonths();
            var that = this;
            that.dateTime = new Date().Format("yyyy-MM-dd");
            that.initList();
            $("body").delegate(".nav-tabs li a", "click", function () {
                var dateTime = $(this).text();
                if (dateTime == "今天") {
                    that.dateTime= new Date().Format("yyyy-MM-dd");
                } else if(dateTime == "本月") {
                    that.dateTime= new Date().Format("yyyy-MM");
                } else {
                    that.dateTime = dateTime;
                }
                that.initList();
            });
        }
    });
</script>

</body>
</html>